#!/bin/sh

#
# This script creates and run the pf4j-spring demo.
#

# 测试用
app-dist/bin/startServer.sh stop

# create artifacts using maven
mvn clean package -DskipTests

# create demo-dist folder
rm -rf app-dist
mkdir -p app-dist/plugins
mkdir -p app-dist/bin
mkdir -p app-dist/conf
mkdir -p app-dist/log
touch app-dist/log/pf4j-spring-demo.log

cp bin/startServer.sh app-dist/bin
chmod 755 app-dist/bin/startServer.sh

cp app/src/main/resources/* app-dist/conf

# copy artifacts to demo-dist folder
cp app/target/app-*.zip app-dist/
#cp plugins/plugin-spiderman/target/plugin-spiderman-*.zip app-dist/plugins/
cp plugins/enabled.txt app-dist/plugins/
cp plugins/disabled.txt app-dist/plugins/

cd app-dist

# unzip app
jar xf app-*.zip
rm app-*.zip

# run demo
mv app-*-SNAPSHOT.jar pf4j-spring-demo.jar
#java -jar pf4j-spring-demo.jar

bash bin/startServer.sh start

tail -200f log/pf4j-spring-demo.log

cd -
